<?php
session_start();
?>
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>

        <style type="text/css">

            body{
                min-width:800px;
                width:auto!important;
                width:800px;
                height:5000px;
                background-image:url(../img/sharp_edge.png);
                background-repeat:repeat;
            }

            label{
                color:white;
            }

        </style>

    </head>
    <body>
        <?php
        include 'Include.php';
        include 'navBar.php';
        include_once '../model/model_sql.php';
        $modelSQL = new SQLBlog();
        $matrice = $modelSQL->AfficherDonneesUtilisateurs($_SESSION['id']);
        ?>
        <div class="container">
            <?php
            if (isset($_GET["successUSER"]) && strcmp($_GET["successUSER"], "1") == 0) {
                echo "<p style=\"color:white;\">Modification du profil réussi</p>";
            } else if (isset($_GET["successMDP"]) && strcmp($_GET["successMDP"], "1") == 0) {
                echo "<p style=\"color:white;\">modification du mot de passe réussi</p>";
            } else {
                ?>
                <form action="../controleur/controleurModifUser.php" method="POST">
                    <div class="row">
                        <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                            <label for="nom">Nom</label>
                            <input name ="nom" type="text" id="Nom" class="form-control" placeholder="Enter nom" maxlength="20" required value=<?php
                            if (isset($_GET['nom'])) {
                                echo $_GET['nom'];
                            } else
                                echo $matrice[0]['nom'];
                            ?>>
                        </div>
                        <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                            <?php
                            if (isset($_GET['messageEnom'])) {
                                echo ("<br/><p style=\"color:red;padding-top:10px;\">" . $_GET['messageEnom'] . "</p>");
                            }
                            ?>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                            <label for="prenom">Prenom</label>
                            <input name ="prenom" type="text" id="Prenom" class="form-control" placeholder="Enter prenom" maxlength="20" required value=<?php
                            if (isset($_GET['prenom']))
                                echo $_GET['prenom'];
                            else
                                echo $matrice[0]['prenom'];
                            ?>>
                        </div>
                        <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                            <?php
                            if (isset($_GET['messageEprenom'])) {
                                echo ("<br/><p style=\"color:red;padding-top:10px;\">" . $_GET['messageEprenom'] . "</p>");
                            }
                            ?>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                            <label for="datepicker">date de Naissance</label>            
                            <input  name ="dateNaissance" type="text" class="form-control" readonly id="datepicker" placeholder="Entrer date de naissance" required value=<?php
                            if (isset($_GET['dateDeNaissance']))
                                echo $_GET['dateDeNaissance'];
                            else
                                echo date("d-m-Y", strtotime($matrice[0]['dateDeNaissance']));
                            ?>>                    
                            <script>
                                $(function() {
                                    $("#datepicker").datepicker({dateFormat: "dd/mm/yy"});
                                });</script>
                        </div>
                        <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                            <label for="email">Email address</label>
                            <input name ="email" type="email" class="form-control" id="email" readonly maxlength="100" placeholder="Enter email" required value=<?php
                            if (isset($_GET['email']))
                                echo $_GET['email'];
                            else
                                echo $matrice[0]['email'];
                            ?>>
                        </div>
                        <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                            <?php
                            if (isset($_GET['messageEemail'])) {
                                echo ("<br/><p style=\"color:red;padding-top:10px;\">" . $_GET['messageEemail'] . "</p>");
                            }
                            ?>
                        </div>
                    </div>
                    <br/>
                    <p><button type="submit" class="btn btn-default">Modifier le profil</button></p>
                </form>
                <div>
                    <a class="btn btn-primary" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
                        modifier mot de passe
                    </a>
                </div>
                <div class="collapse" id="collapseExample">
                    <form method="POST" action="../controleur/controleurModifMDP.php">
                        <div class="row">
                            <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                                <label for="lastPassword">Ancien mot de passe</label>
                                <input name ="lastPassword" type="password" class="form-control" maxlength="50" id="lastPassword" placeholder="Entrer l'ancien mot de passe" required >
                            </div>
                            <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                                <?php
                                if (isset($_GET['messageEpasswordLast'])) {
                                    echo ("<br/><p style=\"color:red;padding-top:10px;\">" . $_GET['messageEpasswordLast'] . "</p>");
                                }
                                ?>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                                <label for="password">Password</label>
                                <input name ="password" type="password" class="form-control" id="password" maxlength="50" placeholder="Entrer password" required >
                            </div>
                            <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                                <?php
                                if (isset($_GET['messageEpassword'])) {
                                    echo ("<br/><p style=\"color:red;padding-top:10px;\">" . $_GET['messageEpassword'] . "</p>");
                                }
                                ?>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                                <label for="password2">Password 2</label>
                                <input name ="password2" type="password" class="form-control" id="password2" maxlength="50" placeholder="Entrer 2eme password" required >
                            </div>
                            <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                                <?php
                                if (isset($_GET['messageEpassword2'])) {
                                    echo ("<br/><p style=\"color:red;padding-top:10px;\">" . $_GET['messageEpassword2'] . "</p>");
                                }
                                ?>
                            </div>
                        </div>
                        <br/>
                        <p><button type="submit" class="btn btn-default">Modifier le mot de passe</button></p>
                    </form>
                </div>
            <?php } ?>
        </div>

    </body>
</html>
